CREATE TABLE "record"
(
    "id"           int8 NOT NULL,
    "version"      int8,
    "domain"       varchar(100) COLLATE "pg_catalog"."default",
    "action"       int2,
    "content"      jsonb,
    "date_synced"  timestamp(6),
    "date_created" timestamp(6),
    PRIMARY KEY ("id", "date_synced"),
    UNIQUE ("domain", "date_synced", "action", "version")
);

DO
$$
BEGIN
	IF EXISTS ( SELECT * FROM pg_available_extensions WHERE "name" = 'timescaledb' ) THEN
        PERFORM create_hypertable('record', 'date_synced');
END IF;
END;
$$
LANGUAGE plpgsql;


CREATE INDEX ON "record"("date_synced" desc);